package com.horizon.im.imClient.clientBuilder;

import com.horizon.im.common.bean.msg.ProtoMsg;
import com.horizon.im.imClient.client.ClientSession;
import lombok.Data;

//基础builder中包括一些大家都有的信息比如：
//1.HeadType,2.seqId,3.sessionId
@Data
public class BaseBuilder {
    protected ProtoMsg.HeadType type;
    private long seqId;
    private ClientSession session;

    public BaseBuilder(
            ProtoMsg.HeadType type,
            ClientSession session)
    {
        this.type = type;
        this.session = session;
    }

    //构建消息基础部分
    public ProtoMsg.Message buildCommand(long seqId) {
        this.seqId = seqId;

        ProtoMsg.Message.Builder mb =
                ProtoMsg.Message
                .newBuilder()
                .setType(type)
                .setSessionId(session.getSessionId())
                .setSequence(seqId);
        return mb.buildPartial();
    }
}
